   <template>
	<view>
		<view class="xq-img" v-if="data.picture">
			<image class="xqpic" :src="data.picture" mode="widthFix"></image>
		</view>
		<view class="anquan">
			<view :class="'xq-title fontsize'+fontsizedetail" >{{data.title}}</view>
			<view  :class="'xq-otr fontsize'+fontsizedetail">
				发布时间：{{data.updateTime}}
			</view>
			<view>
				<wxParse :className="'xq-cont fontsize'+fontsizedetail" :content="data.content" @preview="preview" @navigate="navigate" />
			</view>
		</view>
		<view class="boot">
			<view class="fonts bootchild list-icon" @tap="showfont">
				<text class="list-icon">&#xe735;</text></view>
			<view class="shoucang bootchild list-icon" @click="isaddfn">
				<text class="list-icon" v-if="!isadd">&#xe71f;</text>
				<text class="list-icon aboutadd" v-else>&#xe666;</text>
			</view>
			<!-- <view class="sharebtn bootchild list-icon" @click="showshare">
				<text class="list-icon">&#xe622;</text>
			</view> -->
		</view>
		<view class="font" v-show="isshowfont">
			<detailFontsize v-on:closefont="closefont"></detailFontsize>
		</view>
	<!-- 	<view class="share" v-show="isshowshare">
			<view class="sharebox">
				<view class="sharetodo" @click="sharewx('WXSceneSession')">微信</view>
				<view class="sharetodo" @click="sharewx('WXSenceTimeline')">微信朋友圈</view>
			</view>
			<view class="close" @click="closeshare">关闭</view>
		</view> -->
	</view>
</template>

<script>
	import {common} from '@/common/publish.js';
	import {mapState,mapMutations} from 'vuex';
	import wxParse from 'mpvue-wxparse'
	import detailFontsize from '@/components/detail-fontsize/detail-fontsize.vue';
	export default {
		components:{
			detailFontsize,
			wxParse
		},
		data() {
			return {
				type:'',
				id:'',
				data:{},
				isshowfont:false,
				isshowshare:false,
				href:'',
				isadd:false,
				unionId:'',
				islogin:''
			};
		},
		onLoad(event) {
			var that = this;
			that.type = event.type
			that.id = event.id;
			uni.getStorage({
				key:'unionId',
				success(res) {
					that.unionId = res.data;
				}
			})
			uni.getStorage({
				key:'islogin',
				success(res) {
					console.log(res)
					that.islogin = res.data;
				}
			})
			if(event.type=='lession'){
				this.lession(event.id,event.type)
			}else if(event.type == 'project'){
				this.project(event.id,event.type)
			}else if(event.type == 'projectlist'){
				this.projectlist(event.id,event.type)
			}else if(event.type == 'index'){
				this.getindex(event.id,event.type)
			}else if(event.type == 'qyzt'){
				this.getqyzt(event.id,event.type)
			}
		},
		//分享
		onShareAppMessage(res){
			let that = this;
			return{
				title:data.title,
				path:'/pages/xq/xq?type='+that.type+'&id='+that.id
			}
		},
		methods: {
			preview(src, e) {
			  // do something
			  console.log('do something')
			},
			navigate(href, e) {
			   uni.navigateTo({
			   	url: '/pages/webview/webview?url='+href
			   });
			},
			isaddfn(){
				var that = this;
				if(that.islogin){
					if(this.isadd){
						//取消
						that.isadd = false;
						uni.request({
							url:common.csurl+'/api/collect/cancel.json',
							data:{
								unionId:that.unionId,
								type:that.type,
								collectId:that.data.id
							},
							success(res) {
								if(res.data){
									that.isadd = false;
								}
							}
						})
						
					}else{
						//收藏
						that.isadd = true;
						uni.request({
							url:common.csurl+'/api/collect/save.json',
							data:{
								unionId:that.unionId,
								type:that.type,
								collectId:that.data.id,
								title:that.data.title,
								picture:that.data.picture,
								web :0
							},
							success(res) {
								if(res.data){
									that.isadd = true;
								}
							}
						})
					}
				}else{
					uni.showToast({
						title: '收藏需要登陆',
						icon:'none',
						duration: 1500
					});
				}
			},
			//课程
			lession:function(id,who){
				uni.request({
					url: common.localurl+'/api/topic/topic.json', 
					data:{topicId:id},
					method:'GET',
					dataType:'json',
					success: (res) => {
						this.data = res.data.data;
						this.data.updateTime = common.format(this.data.updateTime)
						var href = common.localurl+'/api/lessionList.htm?id='+ id;
						this.abouttitle(this,href)
						this.dolishi(this,this.data,who,false)
					}
				});
			},
			//项目详情
			project:function(id,who){
				uni.request({
					url: common.localurl+'/api/project/project.json', 
					data:{projectId:id},
					method:'GET',
					dataType:'json',
					success: (res) => {
						this.data = res.data.data.project;
						this.data.updateTime = common.format(this.data.updateTime)
						this.data.picture = this.data.contentpicture;
						var href = common.localurl+'/api/proDetail.htm?type=0&id='+id
						this.abouttitle(this,href)
						this.dolishi(this,this.data,who,false)
					}
				});
			},
			//项目动态详情
			projectlist:function(id,who){
				uni.request({
					url: common.localurl+'/api/project/projectDynamic.json', 
					data:{projectDynamicId:id},
					method:'GET',
					dataType:'json',
					success: (res) => {
						this.data = res.data;
						this.data.updateTime = common.format(this.data.updateTime)
						var href=common.localurl+'/api/proDetail.htm?type=1&id='+id
						this.abouttitle(this,href)
						this.dolishi(this,this.data,who,false)
					}
				});
			},
			getindex(id,who){
				uni.request({
					url: common.csurl2+'/api/newsCentre/homePageNews.json', 
					data:{id:id},
					method:'GET',
					dataType:'json',
					success: (res) => {
						this.data = res.data;
						var link = this.data.picture
						var	reg = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|-)+)/g;
						var wherefrom = reg.test(link)
						if(!wherefrom&&link){
							this.data.picture=common.csurl2+this.data.picture
						}
						var href=common.csurl+'/api/indexshare.htm?type=index&id='+id  //需要重新写此页面
						this.abouttitle(this,href)
						this.dolishi(this,this.data,who,false)
					}
				});
			},
			getqyzt(id,who){
				uni.request({
					url: common.csurl2+'/api/Frontiers/detail.json', 
					data:{frontiersId:id},
					method:'GET',
					dataType:'json',
					success: (res) => {
						this.data = res.data.data;
						var link = this.data.picture
						var	reg = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|-)+)/g;
						var wherefrom = reg.test(link)
						if(!wherefrom&&link){
							this.data.picture=common.csurl2+this.data.picture
						}
						console.log(this.data.picture)
						this.data.updateTime = this.data.uploadTime;
						var href=common.csurl+'/api/indexshare.htm?type=qyzt&id='+id  //需要重新写此页面
						this.abouttitle(this,href)
						this.dolishi(this,this.data,who,false)
					}
				});
			},
			abouttitle:function(that,href){
				that.href = href
				uni.setNavigationBarTitle({
					title: that.data.title
				});
			},
			dolishi(that,data,who,isweb){
				uni.getStorage({
					key:'uerInfo',
					success(res) {
						if(res.data){
							that.isshoucang(who,data.id,that.unionId)
						}
					}
				})
				uni.getStorage({
					key:'lishi',
					success(res) {
						var addarr = {key:data,who:who,isweb:isweb};
						//判定是否存在此条信息
						var isok = true;
						for (var s=0;s<res.data.length;s++) {
							if(res.data[s].key.id == data.id){
								res.data.splice(s,1)
								isok = false;
								res.data.unshift(addarr)
								break;
							}
						}
						if(isok){
							res.data.unshift(addarr)
							if(res.data.length>100){
								res.data.pop()
							}
						}
						uni.setStorage({
							key:'lishi',
							data:res.data,
							success(res) {
								
							}
						})
					},
					fail(res) {
						uni.setStorage({
							key:'lishi',
							data:[{key:data,who:who,isweb:isweb}],
							success() {
								
							}
						})
					}
				})
			},
			sharewx(who){
				var that = this;
				uni.getProvider({
					service: 'share',
					success: function (res) {
						console.log(JSON.stringify(res));
						if (~res.provider.indexOf('weixin')) {
							uni.share({
								provider: "weixin",
								scene: who,
								type: 0,
								href: that.href,
								title: '教育之弦',
								summary: that.data.title,
								imageUrl: common.localurl+"/assets/front/image/jyzxlogo.jpg",
								success: function (res) {
									console.log("success:" + JSON.stringify(res));
									that.isshowshare =false;
								},
								fail: function (err) {
									console.log("fail:" + JSON.stringify(err));
								}
							});
						}
					}
				});
				
			},
			closefont(){
				console.log(22)
				this.isshowfont =false;
			},
			showfont(){
				console.log(11)
				this.isshowfont =true;
			},
			closeshare(){
				this.isshowshare =false;
			},
			showshare(){
				this.isshowshare =true;
			},
			isshoucang(who,collectId,unionId){
				var that = this;
				uni.request({
					url:common.csurl+'/api/collect/collectDetail.json',
					data:{
						type:who,
						collectId:collectId,
						unionId:unionId
					},
					success(res) {
						if(res.data){
							that.isadd = true;
						}
					}
				})
			}
		},
		computed:{
			...mapState(['fontsizedetail'])
		}
	}
</script>

<style lang="scss">
	@import "../../node_modules/mpvue-wxparse/src/wxParse.css";
	@import '@/common/publish.scss';
	@include fontsizefn(".xq-title",36upx);
	@include fontsizefn(".xq-otr",30upx);
	@include fontsizefn(".xq-cont",36upx);
	@font-face {
		font-family: texticons;
		font-weight: normal;
		font-style: normal;
		src: url('../../static/font/iconfont.ttf') format('truetype');
	}
	page{
		background-color: $bgcolor;
	}
	.xq-img{
		width:750upx;
	}
	.xqpic{
		width:100%;
	}
	.anquan{
		padding:0 24upx;
	}
	.xq-title{
		line-height:60upx;
		color:$titlecolor;
	}
	.xq-otr{
		color:$timecolor;
		line-height:50upx;
	}
	.xq-cont{
		margin-bottom:80upx;
	}
	.boot{
		position:fixed;
		left:0;
		bottom:0;
		width:750upx;
		height:120upx;
		display: flex;
		flex-direction:row;
		flex-wrap:nowrap ;
		justify-content:space-between;
		align-items:flex-start;
		line-height:120upx;
		background-color:#fff;
		border-top:1px solid #fbfbfb;
		z-index:10;
	}
	.bootchild{
		text-align:center;
		width:33.3%;
	}
	.share{
		position:fixed;
		left:0;
		bottom:0;
		height:300upx;
		width:750upx;
		background-color:#fff;
		border-top:1px solid #fbfbfb;
		z-index:11;
	}
	.sharebox{
		width:100%;
	}
	.sharetodo{
		width:750upx;
		height:100upx;
		line-height:100upx;
		font-size:32upx;
		color:$fontblue;
		text-align: center;
		border-bottom:1px solid #ccc;
	}
	.list-icon {
		width: 200upx;
		height: 120upx;
		line-height: 114upx;
		font-size: 46upx;
		color: $fontblue;
		text-align: center;
		font-family: texticons;
		margin-right: 20upx;
		display:inline-block;
		margin:0 auto;
	}
	.aboutadd{
		font-size:44upx;
	}
	.close{
		text-align: center;
		color:$fontblue;
		position: absolute;
		bottom:0;
		left:0;
		width:750upx;
		height:100upx;
		font-size:32upx;
		line-height:100upx;
		background-color:$bgcolor;
	}
</style>
